using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

//有这行生成的脚本都是UTF-8形式的

namespace MyGame
{
    public class LoadScene : MonoBehaviour
    {
        public string loadSceneName;


        
        public void Awake()
        {
            DontDestroyOnLoad(this.gameObject);
        }

        void Start()
        {
            StartCoroutine(LoadSceneAsync(loadSceneName));
        }

        IEnumerator LoadSceneAsync(string sceneName)
        {
            AsyncOperation asyncOp = SceneManager.LoadSceneAsync(sceneName);
            asyncOp.allowSceneActivation = false; // 禁止自动跳转

            while (!asyncOp.isDone)
            {
                float progress = Mathf.Clamp01(asyncOp.progress / 0.9f); // 进度0~1
                Debug.Log($"加载进度: {progress * 100}%");

                if (progress >= 0.9f)
                {
                    asyncOp.allowSceneActivation = true; // 手动触发场景切换
                }
                yield return null;
            }
        }
    }
}


 
